/* 包含了所哟action (工厂函数) */

import { ADD_COMMENT, DELETE_COMMENT, RECIVE_COMMENTS } from './action-type'

//同步添加
export const addComment = (commont) => ({
    type: ADD_COMMENT, data: commont
})
//同步删除
export const deleteComment = (index) => ({
    type: DELETE_COMMENT, data: index
})


//同步接收comments 仅内部使用
const reciveComments = (comments) => (
    { type: RECIVE_COMMENTS, data: comments }
)

//异步从后台获取 数据
export const getComment = () => {
    return dispatch => {
        setTimeout(() => {
            const comments = [
                { username: 'Tom', content: 'Rect 挺好的' },
                { username: 'Jack', content: 'Rect 太难了' }
            ]
            //分发同步action
            dispatch(reciveComments(comments))
        }, 1000)
    }
}